package kr.hkit.summary_java.erp;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import kr.hkit.summary_java.erp.serviceui.PanelCodeTitleUI;
import kr.hkit.summary_java.erp.serviceui.PanelDepartmentUI;
import kr.hkit.summary_java.erp.serviceui.PanelEmployeeUI;

public class TestFrame extends JFrame implements ActionListener {

	private JPanel contentPane;
	private JMenuBar mainMenu;
	private JMenu EmpMenu;
	private JMenu DeptMenu;
	private JMenuItem addEmp;
	private JMenuItem deleteEmp;
	private JMenuItem updateEmp;
	private JMenuItem searchEmp;
	private JMenuItem prnEmp;
	private JMenuItem addDept;
	private JMenuItem deleteDept;
	private JMenuItem updateDept;
	private JMenuItem searchDept;
	private JMenuItem prnDept;
	private JPanel inputPanel;
	private JMenu TitleMenu;
	private JMenuItem addTitle;
	private JMenuItem deleteTitle;
	private JMenuItem updateTitle;
	private JMenuItem searchTitle;
	private JMenuItem prnTitle;

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					TestFrame frame = new TestFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public TestFrame() {
		initialize();
	}

	private void initialize() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 500);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new BorderLayout(0, 0));

		mainMenu = new JMenuBar();
		contentPane.add(mainMenu, BorderLayout.NORTH);

		EmpMenu = new JMenu("사원관리");
		mainMenu.add(EmpMenu);

		addEmp = new JMenuItem("추가");
		addEmp.addActionListener(this);
		EmpMenu.add(addEmp);

		deleteEmp = new JMenuItem("삭제");
		deleteEmp.addActionListener(this);
		EmpMenu.add(deleteEmp);

		updateEmp = new JMenuItem("수정");
		updateEmp.addActionListener(this);
		EmpMenu.add(updateEmp);

		searchEmp = new JMenuItem("검색");
		searchEmp.addActionListener(this);
		EmpMenu.add(searchEmp);

		prnEmp = new JMenuItem("출력");
		prnEmp.addActionListener(this);
		EmpMenu.add(prnEmp);

		DeptMenu = new JMenu("부서관리");
		mainMenu.add(DeptMenu);

		addDept = new JMenuItem("추가");
		addDept.addActionListener(this);
		DeptMenu.add(addDept);

		deleteDept = new JMenuItem("삭제");
		deleteDept.addActionListener(this);
		DeptMenu.add(deleteDept);

		updateDept = new JMenuItem("수정");
		updateDept.addActionListener(this);
		DeptMenu.add(updateDept);

		searchDept = new JMenuItem("검색");
		searchDept.addActionListener(this);
		DeptMenu.add(searchDept);

		prnDept = new JMenuItem("출력");
		prnDept.addActionListener(this);
		DeptMenu.add(prnDept);

		TitleMenu = new JMenu("직책관리");
		mainMenu.add(TitleMenu);

		addTitle = new JMenuItem("추가");
		addTitle.addActionListener(this);
		TitleMenu.add(addTitle);

		deleteTitle = new JMenuItem("삭제");
		deleteTitle.addActionListener(this);
		TitleMenu.add(deleteTitle);

		updateTitle = new JMenuItem("수정");
		updateTitle.addActionListener(this);
		TitleMenu.add(updateTitle);

		searchTitle = new JMenuItem("검색");
		searchTitle.addActionListener(this);
		TitleMenu.add(searchTitle);

		prnTitle = new JMenuItem("출력");
		prnTitle.addActionListener(this);
		TitleMenu.add(prnTitle);

		inputPanel = new JPanel();
		contentPane.add(inputPanel);
		inputPanel.setLayout(new BorderLayout(0, 0));
		
	}

	public void actionPerformed(ActionEvent e) {
		inputPanel.removeAll();
		
		if (e.getSource() == addTitle) {
			actionPerformedAddTitle(e);
		}
		if (e.getSource() == updateTitle) {
			actionPerformedUpdateTitle(e);
		}
		if (e.getSource() == deleteTitle) {
			actionPerformedDeleteTitle(e);
		}
		if (e.getSource() == searchTitle) {
			actionPerformedSearchTitle(e);
		}
		if (e.getSource() == prnTitle) {
			actionPerformedPrnTitle(e);
		}
		if (e.getSource() == updateEmp) {
			actionPerformedUpdateEmp(e);
		}
		if (e.getSource() == addEmp) {
			actionPerformedAddEmp(e);
		}
		if (e.getSource() == searchEmp) {
			actionPerformedSearchEmp(e);
		}
		if (e.getSource() == prnEmp) {
			actionPerformedPrnEmp(e);
		}
		if (e.getSource() == deleteEmp) {
			actionPerformedDeleteEmp(e);
		}
		if (e.getSource() == searchDept) {
			actionPerformedSearchDept(e);
		}
		if (e.getSource() == prnDept) {
			actionPerformedPrnDept(e);
		}
		if (e.getSource() == updateDept) {
			actionPerformedUpdateDept(e);
		}
		if (e.getSource() == deleteDept) {
			actionPerformedDeleteDept(e);
		}
		if (e.getSource() == addDept) {
			actionPerformedAddDept(e);
		}
		
		revalidate();
		pack();
	}

	protected void actionPerformedAddDept(ActionEvent e) {
		inputPanel.add(new PanelDepartmentUI("추가"), BorderLayout.CENTER);
	}

	protected void actionPerformedDeleteDept(ActionEvent e) {
		inputPanel.add(new PanelDepartmentUI("삭제"), BorderLayout.CENTER);
	}

	protected void actionPerformedUpdateDept(ActionEvent e) {
		inputPanel.add(new PanelDepartmentUI("수정"), BorderLayout.CENTER);
	}

	protected void actionPerformedPrnDept(ActionEvent e) {
		inputPanel.add(new PrnDept(), BorderLayout.CENTER);
	}

	protected void actionPerformedSearchDept(ActionEvent e) {
		inputPanel.add(new PanelDepartmentUI("검색"), BorderLayout.CENTER);
	}

	protected void actionPerformedDeleteEmp(ActionEvent e) {
		inputPanel.add(new PanelEmployeeUI("삭제"), BorderLayout.CENTER);
	}

	protected void actionPerformedPrnEmp(ActionEvent e) {
		inputPanel.add(new PrnEmp(), BorderLayout.CENTER);
	}

	protected void actionPerformedSearchEmp(ActionEvent e) {
		inputPanel.add(new PanelEmployeeUI("검색"), BorderLayout.CENTER);
	}

	protected void actionPerformedAddEmp(ActionEvent e) {
		inputPanel.add(new PanelEmployeeUI("추가"), BorderLayout.CENTER);
	}

	protected void actionPerformedUpdateEmp(ActionEvent e) {
		inputPanel.add(new PanelEmployeeUI("수정"), BorderLayout.CENTER);
	}

	protected void actionPerformedPrnTitle(ActionEvent e) {
		inputPanel.add(new PrnCodeTitle(), BorderLayout.CENTER);
	}

	protected void actionPerformedSearchTitle(ActionEvent e) {
		inputPanel.add(new PanelCodeTitleUI("검색"), BorderLayout.CENTER);
	}

	protected void actionPerformedDeleteTitle(ActionEvent e) {
		inputPanel.add(new PanelCodeTitleUI("삭제"), BorderLayout.CENTER);
	}

	protected void actionPerformedUpdateTitle(ActionEvent e) {
		inputPanel.add(new PanelCodeTitleUI("수정"), BorderLayout.CENTER);
	}

	protected void actionPerformedAddTitle(ActionEvent e) {
		inputPanel.add(new PanelCodeTitleUI("추가"), BorderLayout.CENTER);
	}
}
